<template>
  <section>
    <div class="page-head">
      <div class="page-head-inner">
        <img src="../../static/assets/logo.png" @click="fnBackIndex">
        <ul class="head-nav" v-if="!isLogin">
          <li @click="fnHasLogDialog">登录</li>
          <li class="nav-pile">|</li>
          <li @click="fnHasRegDialog">注册</li>
          <li class="nav-pile">|</li>
          <li @click="fnHasAboutDialog">关于</li>
        </ul>
        <ul class="head-nav" v-else>
          <li>张全蛋</li>
          <li class="nav-pile">|</li>
          <li @click="fnClearLogin">退出</li>
          <li class="nav-pile">|</li>
          <li @click="fnHasAboutDialog">关于</li>
        </ul>
      </div>
    </div>
    <div class="page-container">
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </div>
    <div class="page-foot">@ 2017 amber KYN</div>

    <!--登录弹框-->
    <my-dialog :hasLogDialog="hasLogDialog" :title="dialogTitle" @emit-close-dialog="fnCloseDialog('hasLogDialog')">
      <login></login>
    </my-dialog>
    <!--注册弹框-->
    <my-dialog :hasLogDialog="hasRegDialog" :title="dialogTitle" @emit-close-dialog="fnCloseDialog('hasRegDialog')">
      <register></register>
    </my-dialog>
    <!--关于我们弹框-->
    <my-dialog :hasLogDialog="hasAboutDialog" :title="dialogTitle" @emit-close-dialog="fnCloseDialog('hasAboutDialog')">
      <about-us></about-us>
    </my-dialog>
  </section>
</template>

<script lang='ts'>
  import Vue from 'vue'
  import Component from 'vue-class-component'
  import Dialog from './Dialog.vue'
  import Login from './Login.vue'
  import Register from './Register.vue'
  import AboutUs from './AboutUs.vue'

  //引入组件
  @Component({
    components: {
      'myDialog' : Dialog,
      'login' : Login,
      'register' : Register,
      'about-us' : AboutUs
    }
  })
  export default class Layout extends Vue {
    //控制dialog是否显示
    hasLogDialog : boolean = false
    hasRegDialog : boolean = false
    hasAboutDialog : boolean = false

    //是否登录
    isLogin : boolean = false

    //dialog标题
    dialogTitle : string = ''

    //methods
    //控制登录dialog是否显示
    fnHasLogDialog():void{
      this.dialogTitle = '登录'
      this.hasLogDialog = true
    }

    //控制注册dialog是否显示
    fnHasRegDialog():void{
      this.dialogTitle = '注册'
      this.hasRegDialog = true
    }

    //控制关于我们dialog是否显示
    fnHasAboutDialog():void{
      this.dialogTitle = '关于我们'
      this.hasAboutDialog = true
    }

    //关闭dialog
    fnCloseDialog(dialogId):void {
      this[dialogId] = false
    }

    //退出登录
    fnClearLogin():void {
      sessionStorage.setItem('user','')
      this.$router.go(0)
    }

    //返回首页
    fnBackIndex():void{
      this.$router.push({path:'/'})
    }

    //生命周期 mounted
    mounted () {
      if (sessionStorage.getItem('user')) {
        this.isLogin = true
      } else {
        this.isLogin = false
      }
    }
  }
</script>

<style lang="scss">
  html, body, div, span, applet, object, iframe,
  h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  a, abbr, acronym, address, big, cite, code,
  del, dfn, em, font, img, ins, kbd, q, s, samp,
  small, strike, strong, sub, sup, tt, var,
  b, u, i, center,
  dl, dt, dd, ol, ul, li,
  fieldset, form, label, legend,
  table, caption, tbody, tfoot, thead, tr, th, td,p {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    vertical-align: baseline;
    background: transparent;
  }

  article,aside,details,figcaption,figure,
  footer,header,hgroup,menu,nav,section {
    display: block;
  }

  body{
    line-height: 1;
    background: #f0f2f5;
    font-family: "Helvetica Neue",Helvetica,Arial,"
    Hiragino Sans GB","Hiragino Sans GB W3","
    Microsoft YaHei UI","Microsoft YaHei","
    WenQuanYi Micro Hei",sans-serif;
    font-size: 14px ;
    color: #444;
  }

  .page-head {
    background: #363636;
    color: #b2b2b2;
    height: 80px;
    line-height: 80px;
    width: 100%;

    .page-head-inner{
      width: 90%;
      margin: 0 auto;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;

      img{
        width: 50px;
        height: 50px;
        cursor: pointer;
      }

      .head-nav{
        width: 11%;
        cursor: pointer;
        font-weight: bold;
        list-style: none;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
      }
    }
  }

  .page-foot{
    text-align: center;
    width: 100%;
    height: 60px;
    line-height: 60px;
    background: #e3e4e8;
    clear: both;
    margin-top: 30px;
  }

  .page-container {
    width: 90%;
    margin: 0 auto;
  }

</style>
